package Framework;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;


public class dlg_Ancestor extends JLayeredPane implements ActionListener {
	
	JRootPane root;
	static String CLASS = "dlg_Ancestor"; 
	String DialogName;
	private pnl_Ancestor pane_LastWindow; // The calling window, or a new window if set. 
	ImageIcon img_Background; 		// Background image
	
	public void setimg_Background( String as_image ) {
		img_Background = nv_ImageLoader.loadImage(as_image);
	}
	
	public void paintComponent( Graphics g ) {
		if( img_Background == null ){ 
			setimg_Background("img/bg_dlg.png");
		}
		super.paintComponent(g);
		//super.paintComponent(img_Background);
		g.drawImage(img_Background.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
	}
	
	protected void finalize() throws Throwable {
		debugMessage.log("Object " + CLASS + " Destructed.", 11);
	}

	protected void reset(){
		System.out.println("YOU SHOULD NOT BE HERE");
	}
	
	public void deactivate(){
		// Deactivates panel
		this.getRootPane().setContentPane(pane_LastWindow);
			
		// Calling an action on panel which activated this one.
		ActionEvent x = new ActionEvent(this, 1, CLASS);
		pane_LastWindow.actionPerformed(x);
	}
	
	public void activate(pnl_Ancestor caller){
		// Resetting to initial state  
		this.reset();                  
		// Activates (Runs) dialogue
		this.pane_LastWindow = caller;
		
		root = caller.getRootPane();

		this.validate();
		// Setting the layer to MODAL 
		
		root.setContentPane(this);
		root.repaint();
		 
	}
	
	public void changeReturnWindow(pnl_Ancestor a_newReturn){
		// Changes the return window. 
		// Used in a scenario such as a menu that goes "Would you like to go to this page now?"
		pane_LastWindow = a_newReturn;
	}
	
	public dlg_Ancestor() {
		//Dialog name will be used for Event type-check.	
		this.setBounds(0,0,800,600);
		
	}

	public boolean equals(Object InitialObject){
		// This may need an exception, and should be extended by children.
		dlg_Ancestor ConvertedObject = (dlg_Ancestor) InitialObject;
		if (ConvertedObject.pane_LastWindow == this.pane_LastWindow){
			return true;
		}
		return false;
	}
	
	
	public void actionPerformed(ActionEvent arg0) {
		System.out.println("YoU HSOULDNT BE HERE!!1");
	}
	
}
